<?php 
/**
* @package DomModuleAdmin.Test
* @author  Oliver Leisalu, Inditel Meedia OÜ
*/
class DMATestModule1 {

	public function getBackEnd() {

		$DMA = new DMA('Muusika moodul',SITE_URL.'moduleAdmin.php?', $this);
		
		$main = new DMASection('mainSect', 'Peasektsioon', $this, 'bg_main'); 
		$DMA->addSection( $main, true );
		
		$main->addSection( new DMASection('tabtest','Tab test ',$this, 'bg_tabTest'));
		$main->addSection( new DMASection('settest','Set test', $this, 'bg_setTest'));
		$main->addSection( new DMASection('multisettest','Multiple Set test', $this, 'bg_multisetTest'));
		$main->addSection( new DMASection('listtest','List',$this, 'bg_listTest'));
		
		
		$main = new DMASection('fieldTest', 'FieldTests');
		$DMA->addSection( $main );
		
		$main->addSection( new DMASection('wizard','Wizard',$this, 'bg_wizard'), true );
		$main->addSection( new DMASection('sekts2','Sekts2',$this, 'bg_fieldtest2'));
		$main->addSection( new DMASection('htmltest','HTML test',$this, 'bg_fieldHtmlTest'));
		
		
		$main = new DMASection('otherTest', 'Muud');
		$DMA->addSection( $main );
		
		$main->addSection( new DMASection('other1','Muu 1'), true );
		$main->addSection( new DMASection('other2','Muu 2'));
		
		
		return $DMA->getFrontEnd();
	}
	
	public function bg_main( DMASection $section ) {
		$set = new DMASet('mainset','Main set'); 
		$set->addField( new DMAFieldComment('DMA testimiseks mõeldud klass!') );
		$set->addField( new DMAFieldComment('Kliki kõike ja vaata kas töötab nii nagu eeldatud!') );
		$section->addSet($set);
	}
	
	public function bg_tabTest( DMASection $section ) {
	
		$section->addMessageField( new DMAFieldOk('Kõik on korras!') );
	
		// ---------------------------
		// TABS
		$tab1 = new DMATab('tab1','Tab 1'); $section->addTab($tab1);
		$tab2 = new DMATab('tab2','Tab 2 (main)'); $section->addTab($tab2, true);
		$tab3 = new DMATab('tab3','Tab 3 (empty)'); $section->addTab($tab3);
		$tab4 = new DMATab('tab4','Tab 4 (MultiSet)'); $section->addTab($tab4);
		
		// ---------------------------
		// TAB 1 SET
		$set1 = new DMASet('set1','Tab 1 header set'); 
		
		$set1->addField( new DMAFieldComment('Tab 1 header set?') );
		$tab1->addSet($set1);
		
		$set1 = new DMASet('tab1set','Tab 1 set');
		$tab1->addSet($set1);

		if( $tab1->isSelected() && $set1->getPost('subset') == 1 ) {
			$set1->storePost('subset');
			
			$helper = new DMATestModule1Helper();
			$replSection = new DMASection('subsetsect','subsetsect', $helper, 'otherManager');
			$set1->setReplacingSection( $replSection );
			
			if( $replSection->isFinished() ) {
				$set1->addField( new DMAFieldComment('Eelmises vormis valitud väärtus oli "'.$helper->controlValue.'"') );
			}
		}

		$set1->addField( new DMAFieldSelect('subset', array(0=>'ei', 1=>'jah',2=>'ei tee midagi!'), (int)$set1->getPost('subset') , 'Kuva alam vorm','script','onChange="this.form.submit()"') );
		$set1->addField( new DMAFieldComment('Kui valid jah, siis peab selle asemele kuvatama teinse sektsioon! Uuenema peaks kohe vahetamisel ja valitud väärtus peab säilima!') );
		$set1->addField( new DMAFieldSubmit('choose','Vali') );
		
		$set1 = new DMASet('tab1aset','Tab 1 another set'); 
		$set1->addField( new DMAFieldComment('Teine set, kas toimib?') );
		$tab1->addSet($set1);
		
		// ---------------------------
		// TAB 2 SET
		
		$set2 = new DMASet('set2','Muu'); 
		$tab2->addSet($set2);

		if( $set2->isSubmitted() && $tab2->isSelected() ) {
			$sum = $set2->getPost('number1') + $set2->getPost('number2');
			$set2->addField( new DMAFieldComment('Numbrite summa on '.$sum) );
		}
		
		$set2->addField( new DMAFieldInt('number1',$set2->getPost('number1'),'Kirjutage number 1') );
		$set2->addField( new DMAFieldInt('number2',$set2->getPost('number2'),'Kirjutage number 2') );
		$set2->addField( new DMAFieldSubmit('send2','Arvuta summa!') );
		
		
		// ---------------------------
		// TAB 3 SET
		
		// ---------------------------
		// TAB 4 SET
		
		$set = new DMASet('multitest1','Multiset test 1'); 
		$set->addField( new DMAFieldComment('1') );
		$tab4->addSet($set);
		
		$set = new DMASet('multitest2','Multiset test 2'); 
		$set->addField( new DMAFieldComment('2') );
		$tab4->addSet($set);
		
		$set = new DMASet('multitest3','Multiset test 3'); 
		$set->addField( new DMAFieldComment('3') );
		$tab4->addSet($set);
		
	}
	
	public function bg_setTest( DMASection $section ) {
		
		$selectValues = array(
						array('value'=>'sel1','name'=>'value1', 'level'=>0,'disabled'=>true),
						array('value'=>'sel2','name'=>'value2', 'level'=>1),
						array('value'=>'sel3','name'=>'value3', 'level'=>1),
						array('value'=>'sel4','name'=>'value4', 'level'=>0),
						array('value'=>'sel5','name'=>'value5', 'level'=>1,'disabled'=>true),
						array('value'=>'sel6','name'=>'value6', 'level'=>2)
		);
		
		$set = new DMASet('settestMassive','Set test'); 
		//trace($set->getPost());
		$set->addField( new DMAFieldBrake('Vormi elemendid') );

		$set->addField( new DMAFieldInt('a1', $set->getPost('a1'), 'Number', 'info','Info') );
		$val = $set->getPost('a6');
		$set->addField( new DMAFieldPairInt('a6', $val[0], $val[1], 'Topelt number', 'middle','x','after','px','info','Info') );
		$set->addField( new DMAFieldTextField('a2', $set->getPost('a2'), 'Text', 'info','Info') );
		$set->addField( new DMAFieldPassword('a7', 'Parool', 'info','Info') );
		$set->addField( new DMAFieldCheck('a5', (bool)$set->getPost('a5'), 'Check', 'info','Info') );
		
		
		$set->addField( new DMAFieldBrake('Valikud') );
		$set->addField( new DMAFieldHidden('a8', 'HIDDEN_VALUE'.$set->getPost('a8')) );
		$set->addField( new DMAFieldSelect('a3', $selectValues, $set->getPost('a3'), 'Select', 'info','Info') );
		$set->addField( new DMAFieldMultiSelect('a13', $selectValues, array('sel2'=>1,'sel6'=>1), 'MultiSelect', 'info','Info') );
		$set->addField( new DMAFieldRadio('a4', array('value1','value2','value3'), (int)$set->getPost('a4'), 'Radio', 'info','Info') );
		
		
		
		$set->addField( new DMAFieldBrake('Failid') );
		$set->addField( new DMAFieldImage('<img src="http://localhost/TESTING/watermark.png"></img>','Praegune pilt','cols',3) );
		$set->addField( new DMAFieldFile('a9', 'Fail', 'info','Info') );
		$set->addField( new DMAFieldImage('<img src="http://localhost/TESTING/watermark.png"></img>','Praegune pilt','cols',1) );
		
		$set->addField( new DMAFieldBrake('Spetsiaalsed') );
		$set->addField( new DMAFieldCalendar('a11', $set->getPost('a11'), 'Kalender') );
		$set->addField( new DMAFieldColor('a12', $set->getPost('a12'), 'Värv','info','Info') );
		//$forum = new DomUserManager();
		//$process = new DomProcess( $forum ,'sa');
		//$set->addField( new DMAFieldSearch('a14', array('a'=>'b','aa'=>'bb'), 'Otsing', $process,'limit',3) );
		$set->addField( new DMAFieldBrake('Teksti redaktor') );
		$set->addField( new DMAFieldTextArea('a15', $set->getPost('a15'), 'Text') );
		$set->addField( new DMAFieldTextEditor('a10', $set->getPost('a10'), 'Editor',500,200) );
		
		
		$set->addField( new DMAFieldBrake('Teated') );
		$set->addField( new DMAFieldSupport('Abi') );
		$set->addField( new DMAFieldOk('Ok') );
		$set->addField( new DMAFieldWarning('Hoiatus') );
		$set->addField( new DMAFieldFailed('Ebaõnnestus') );
		$set->addField( new DMAFieldComment('Kommentaar') );
		$set->addField( new DMAFieldTip('Vihje') );
		$set->addField( new DMAFieldRow('nimi','väärtus','info','Info') );
		$set->addField( new DMAFieldSubmit('submit','Saada') );
		
		$set->setSubmitButton('Salvesta');
		$set->setCancelButton('Katkesta');
		
		$section->addSet( $set );
		
	}
	
	public function bg_multisetTest( DMASection $section ) {
		$set = new DMASet('multiset1','Multiset test 1'); 
		$set->addField( new DMAFieldComment('1') );
		$section->addSet($set);
		
		$set = new DMASet('multiset2','Multiset test 2'); 
		$set->addField( new DMAFieldComment('2') );
		$section->addSet($set);
		
		$set = new DMASet('multiset3','Multiset test 3'); 
		$set->addField( new DMAFieldComment('3') );
		$section->addSet($set);
		
		
	}
	
	public function bg_listTest( DMASection $section ) {
	
		$showList = true;
		$set = new DMASet('listSet','List test');$section->addSet($set);
		$set->addField( new DMAFieldTip('Mida testida:') );
		$set->addField( new DMAFieldComment('
				1) Kas peale muutmist toimivad üldised nupud <br />
				2) Kas muutmisel toimib vale valik <br />
				3) Kas leheküljed jäävad samaks peale muutmist <br />
				
		') );
		
		$set->addField( new DMAFieldBrake('Otsing') );
		$set->addField( new DMAFieldTextField('searchword','','Otsisõna') );
		$set->addField( new DMAFieldSelect('seatchselect',array(),'','Mille seast') );
		$set->addField( new DMAFieldCheck('hagus','','Hägus otsing') );
		$set->addField( new DMAFieldSubmit('search','Otsi') );
		
		$list = new DMAList('listVar'); $set->addField( $list );
		$list2 = new DMAList('ls2'); $set->addField( $list2 );
		
		//trace($set->getPost());
		switch( $set->getPost('listVar','action') ) {
			case 'change':
				$list->store();
				$helper = new DMATestModule1Helper();
				$replSection = new DMASection('subsetsect','subsetsect', $helper, 'otherManager');
				$set->setReplacingSection( $replSection );
		
				$showList = $replSection->isFinished();
				if( $showList ) $list->unstore();
			break;
		
		}
		
		if( $showList == true ) {
			
			
			$list->setWidth(600);
			$list->setPerPage(10);
	//trace($set->getPost('listVar'));
			
			$fields = array();
			$fields[] = array('title'=>'Nimi','field'=>'name','action'=>'change','width'=>150,'levels'=>true,'allowOrderBy'=>true);
			$fields[] = array('title'=>'Info','field'=>'info','width'=>150);
			$fields[] = array('width'=>'*');
			$fields[] = array('moveUp','colSpan'=>7,'title'=>'Valikud');
			$fields[] = 'moveDown';
			$fields[] = array('change');
			
			$fields[] = 'delete';
			$fields[] = 'checks';
			$fields[] = array('activate','field'=>'active');
			
			$list->setFields( $fields );
			 
			$list->setButtons( array('selection','activate','deactivete','delete') );

			$data = array();
			$data[] = array('id'=>1, 'name'=>'Esimene', 'info'=>'Info 1','level'=>0);
			$data[] = array('id'=>2, 'name'=>'Teine', 'info'=>'Info 2','level'=>1,'active'=>true);
			$data[] = array('id'=>3, 'name'=>'Kolmas', 'info'=>'Info 3','level'=>1);
			$data[] = array('id'=>4, 'name'=>'Neljas', 'info'=>'Info 4','level'=>1,'active'=>true);
			$data[] = array('id'=>5, 'name'=>'Viies', 'info'=>'Info 5','level'=>2);
			$data[] = array('id'=>6, 'name'=>'Kuues', 'info'=>'Info 6','level'=>2);
			$data[] = array('id'=>7, 'name'=>'Seitsmes', 'info'=>'Info 7','level'=>1,'active'=>true);
			$data[] = array('id'=>8, 'name'=>'Kaheksas', 'info'=>'Info 8','level'=>0,'active'=>true);
			$data[] = array('id'=>9, 'name'=>'Üheksas', 'info'=>'Info 9','level'=>1,'active'=>true);
			$data[] = array('id'=>10, 'name'=>'Kümnes', 'info'=>'Info 10','level'=>2);
			$data[] = array('id'=>11, 'name'=>'Üheteistkümnes', 'info'=>'Info 11','level'=>2,'active'=>true);
			$data[] = array('id'=>12, 'name'=>'Kaheteistkümnes', 'info'=>'Info 12','level'=>1,'active'=>true);
			$data[] = array('id'=>13, 'name'=>'Kolmeteistkümnes', 'info'=>'Info 13','level'=>1,'active'=>true);
			$data[] = array('id'=>14, 'name'=>'Neljateistkümnes', 'info'=>'Info 14','level'=>1);
			$data[] = array('id'=>15, 'name'=>'Viieteistkümnes', 'info'=>'Info 15','level'=>0);
			$list->setData($data);
			
			
			
			$list2->setPerPage(4);
			
			$fields = array();
			$fields[] = array('title'=>'Nimi','field'=>'name','action'=>'change','width'=>200,'levels'=>true);
			$fields[] = array('title'=>'Info','field'=>'info');
			$fields[] = array('change','colSpan'=>3);
			$fields[] = 'delete';
			$fields[] = 'checks';
			$list2->setFields( $fields );
			
			$list2->setButtons( array('selection','delete') );
			$list2->setData($data);
		 }
		 
		
		
	}
	
	public function bg_wizard( DMASection $section ) {
		$set = new DMAWizard('wizardSet','Main set'); $section->addSet($set);
		$steps = array('1.Algus', '2.Vahepeal', '3.Peaaegu','4.Kinnitamine');
		$set->setSteps( $steps );
		$show = true;
		//trace($set->getPost());
		
		switch( $set->getSubmitted() ):
			case 1:
				//trace('manage 1');
			break;
			case 2:
				
				if( $set->getPost('subhere') ) {
					
					$set->storePost('subhere');
					
					$helper = new DMATestModule1Helper();
					$replSection = new DMASection('subsetsect','subsetsect', $helper, 'otherManager');
					$set->setReplacingSection( $replSection );
					
					$replSection->isFinished() ? NULL : $show = false;
				}
			break;
			case 3:
				
				//trace('manage 3');
				switch( $set->getPost('listVar','action') ) {
					case 'change':
						$list = new DMAList('listVar'); $set->addField($list);
						$list->store();
						
						$helper = new DMATestModule1Helper();
						$replSection = new DMASection('subsetsect','subsetsect', $helper, 'otherManager');
						$set->setReplacingSection( $replSection );
				
						$replSection->isFinished() ? $list->unstore() : $show = false;
					break;
				}
			break;
			case 4:
				//trace('manage 4');
				//trace( $set->isFinished() );
			break;
		endswitch;
		
		if( !$show ) return;
		
		switch( $set->getCurrent() ):
			case 1:
				$set->addField( new DMAFieldComment('Wizardi esimene step') );
				$set->addField( new DMAFieldSubmit('subhere','Submit here') );
			break;
			case 2:
				$set->addField( new DMAFieldComment('Wizardi teine step') );
				$set->addField( new DMAFieldInt('int', 10, 'Int') );
				$set->addField( new DMAFieldSubmit('subhere','Submit here') );
			break;
			case 3:
				$set->addField( new DMAFieldComment('Mida testida: <br />
														1) Kontrollida kas lehekülgedel saab liikuda<br />
														2) Kontrollida kas saab muutmist rakendada ja seal valet vastust panna, tagasitulles oleks sama leht.<br />
														3) Toimivad üldised nupud<br />
													') );
				$list = DMAEntity::getItem('listVar');
				if( !$list) {
					$list = new DMAList('listVar'); 
					$set->addField( $list );
				}
				$set->addField( new DMAFieldSubmit('subhere','Submit here') );
				
				
				$list->setWidth(600);
				$list->setPerPage(6);
					
				$fields = array();
				$fields[] = array('title'=>'Nimi','field'=>'name','action'=>'change','width'=>200,'levels'=>true);
				$fields[] = array('title'=>'Info','field'=>'info');
				$fields[] = array('moveUp','colSpan'=>2);
				$fields[] = 'moveDown';
				$fields[] = array('change','colSpan'=>5);
				$fields[] = 'delete';
				$fields[] = 'checks';
				$fields[] = array('activate','field'=>'active');
					
				$list->setFields( $fields );
					 
				$list->setButtons( array('selection','activate','deactivete','delete') );
		
				$data = array();
				$data[] = array('id'=>1, 'name'=>'Esimene', 'info'=>'Info 1','level'=>0);
				$data[] = array('id'=>2, 'name'=>'Teine', 'info'=>'Info 2','level'=>1,'active'=>true);
				$data[] = array('id'=>3, 'name'=>'Kolmas', 'info'=>'Info 3','level'=>1);
				$data[] = array('id'=>4, 'name'=>'Neljas', 'info'=>'Info 4','level'=>1,'active'=>true);
				$data[] = array('id'=>5, 'name'=>'Viies', 'info'=>'Info 5','level'=>2);
				$data[] = array('id'=>6, 'name'=>'Kuues', 'info'=>'Info 6','level'=>2);
				$data[] = array('id'=>7, 'name'=>'Seitsmes', 'info'=>'Info 7','level'=>1,'active'=>true);
				$data[] = array('id'=>8, 'name'=>'Kaheksas', 'info'=>'Info 8','level'=>0,'active'=>true);
				$data[] = array('id'=>9, 'name'=>'Üheksas', 'info'=>'Info 9','level'=>1,'active'=>true);
				$data[] = array('id'=>10, 'name'=>'Kümnes', 'info'=>'Info 10','level'=>2);
				$data[] = array('id'=>11, 'name'=>'Üheteistkümnes', 'info'=>'Info 11','level'=>2,'active'=>true);
				$data[] = array('id'=>12, 'name'=>'Kaheteistkümnes', 'info'=>'Info 12','level'=>1,'active'=>true);
				$data[] = array('id'=>13, 'name'=>'Kolmeteistkümnes', 'info'=>'Info 13','level'=>1,'active'=>true);
				$data[] = array('id'=>14, 'name'=>'Neljateistkümnes', 'info'=>'Info 14','level'=>1);
				$data[] = array('id'=>15, 'name'=>'Viieteistkümnes', 'info'=>'Info 15','level'=>0);
				$list->setData($data);
				
				
			break;
			case 4:
				$set->addField( new DMAFieldComment('Wizardi neljas step') );
				$set->addField( new DMAFieldSubmit('subhere','Submit here') );
			break;
		endswitch;

	}
	
	public function bg_fieldHtmlTest( DMASection $section ) {
		$selectValues = array(
						array('value'=>'sel1','name'=>'value1"sda&"&', 'level'=>0,'disabled'=>true),
						array('value'=>'sel2','name'=>'value2', 'level'=>1),
						array('value'=>'sel3','name'=>'value3', 'level'=>1),
						array('value'=>'sel4','name'=>'value4', 'level'=>0),
						array('value'=>'sel5','name'=>'value5', 'level'=>1,'disabled'=>true),
						array('value'=>'sel6','name'=>'value6', 'level'=>2)
		);
		
		$set = new DMASet('settestMassive','Set test'); 
		
		
		if( $set->isSubmitted() ) {
			$set->addField( new DMAFieldBrake('Vastused'));
			$set->addField( new DMAFieldRow($set->getPost('a2'), 'textField'));
			$set->addField( new DMAFieldRow($set->getPost('a15'), 'textArea'));
			$set->addField( new DMAFieldRow($set->getPost('a10'), 'textEditor'));
		}
		
		
		//trace($set->getPost());
		$set->addField( new DMAFieldBrake('Vormi elemendid') );

		$set->addField( new DMAFieldTextField('a2', $set->getPost('a2') ? $set->getPost('a2') : '"tere" &joi', 'Text', 'info','Info') );

		$set->addField( new DMAFieldSelect('a3', $selectValues, $set->getPost('a3'), 'Select', 'info','Info') );
		$set->addField( new DMAFieldMultiSelect('a13', $selectValues, array('sel2'=>1,'sel6'=>1), 'MultiSelect', 'info','Info') );

		$set->addField( new DMAFieldTextArea('a15', $set->getPost('a15') ? $set->getPost('a15') : '"tere" &joi', 'Text') );
		$set->addField( new DMAFieldTextEditor('a10', $set->getPost('a10') ? $set->getPost('a10') : '"tere" &joi', 'Editor',500,200) );
		

		$set->setSubmitButton('Testi');
		
		$section->addSet( $set );
	}
	
	public function bg_fieldtest2( DMASection $section ) {
	
	}
	
	public function bg_wizard2( DMASection $section ) {
		$set = new DMAWizard('wizardSet','Main set'); $section->addSet($set);
		$steps = array('1.Algus', '2.Vahepeal', '3.Peaaegu','4.Kinnitamine');
		$set->setSteps( $steps );
		$show = true;		
		
		switch( $set->getSubmitted() ):
			case 1:

			break;
			case 2:
				
				
			break;
			case 3:
				

			break;
			case 4:

			break;
		endswitch;
		
		if( !$show ) return;
		
		switch( $set->getCurrent() ):
			case 1:
				$set->addField( new DMAFieldComment('Wizardi esimene step') );

			break;
			case 2:
				$set->addField( new DMAFieldComment('Wizardi teine step') );

			break;
			case 3:
				
			break;
			case 4:
				$set->addField( new DMAFieldComment('Wizardi neljas step') );
			break;
		endswitch;

	}
}

?>